'''
Created on Apr 6, 2011

@author: mwarren1
'''
import wx

import os.path
from wx.tools.dbg import Logger
from maildroplibs import ENABLEDEBUG, DEBUGSTREAM

import resources

debug = Logger('TutorialGUI')
debug.SetStream(DEBUGSTREAM)
debug(enable = ENABLEDEBUG)

class TutorialGUI(wx.Frame):
    '''
    classdocs
    '''


    def __init__(self):
        '''
        Constructor
        '''
        winSize = (670,560)
        nextButtonPos = (570,500)
        prevButtonPos = (485,500)
        systray = "Notification Area"
        
        if 'wxMSW' in wx.PlatformInfo:
            ostype = 'win'
        elif 'wxGTK' in wx.PlatformInfo:
            ostype = 'linux'
            systray = "System Tray"
            nextButtonPos = (570,525)
            prevButtonPos = (475,525)
        elif 'wxMac' in wx.PlatformInfo:
            ostype = 'mac'
            systray = "Doc"
            winSize = (670,585)
            nextButtonPos = (570,525)
            prevButtonPos = (475,525)
        
        
        wx.Frame.__init__(self, None, title = "Tutorial", size=winSize, style=wx.SYSTEM_MENU|wx.CAPTION|wx.CLOSE_BOX|wx.CLIP_CHILDREN)
        icon = resources.MakeIcon(resources.getBoxIconImage())
        self.SetIcon(icon)
        
        panel = wx.Panel(self)
                
        self.tutorialBitmaps = [wx.Bitmap(os.path.join('images',ostype,'tutorial','0lame.png'), wx.BITMAP_TYPE_PNG),
                                wx.Bitmap(os.path.join('images',ostype,'tutorial','1setup.png'), wx.BITMAP_TYPE_PNG),
                                wx.Bitmap(os.path.join('images',ostype,'tutorial','2taskbar.png'), wx.BITMAP_TYPE_PNG),
                                wx.Bitmap(os.path.join('images',ostype,'tutorial','3imap.png'), wx.BITMAP_TYPE_PNG),
                                wx.Bitmap(os.path.join('images',ostype,'tutorial','4filter.png'), wx.BITMAP_TYPE_PNG),
                                wx.Bitmap(os.path.join('images',ostype,'tutorial','5applylabel.png'), wx.BITMAP_TYPE_PNG),
                                wx.Bitmap(os.path.join('images',ostype,'tutorial','6downloadsetup.png'), wx.BITMAP_TYPE_PNG),
                                wx.Bitmap(os.path.join('images',ostype,'tutorial','7email.png'), wx.BITMAP_TYPE_PNG), #wx.Bitmap(os.path.join('images',ostype,'tutorial','7history.png'), wx.BITMAP_TYPE_PNG),
                                wx.Bitmap(os.path.join('images',ostype,'tutorial','8saved.png'), wx.BITMAP_TYPE_PNG),
                                wx.Bitmap(os.path.join('images',ostype,'tutorial','0lame.png'), wx.BITMAP_TYPE_PNG)]
        
        self.tutorialStrings = ["Welcome to MailDrop!",
                                "When first run, MailDrop will need your Email address and password.",
                                "Once setup, MailDrop will run quietly in your "+systray,
                                "Make sure that IMAP is enabled for your email. In Gmail, go to Settings and Enable IMAP",
                                "Next, we'll setup a simple filter to automate MailDrop",
                                "Finally set the filter to move the emails to the right label (\"Dropbox\" by default)",
                                "Different Labels can be setup in Settings to download files to different folders",
                                "Now any email sent with \"Maildrop\" in the subject will be caught by MailDrop",#"The history window will show all emails in the label and files found",
                                "The files will now show up in your Dropbox in the MailDrop folder!",
                                "That\'s it, have fun!"
]
        
        self.current = 0
        self.count = len(self.tutorialStrings)
        
        self.image = wx.StaticBitmap(panel, -1, self.tutorialBitmaps[0], (10,10))
        self.text = wx.StaticText(panel, -1, self.tutorialStrings[0], (20,500))

        self.nextBUTTON = wx.Button(panel, wx.ID_FORWARD, "Next", nextButtonPos)
        self.nextBUTTON.SetDefault()
        self.prevBUTTON = wx.Button(panel, wx.ID_BACKWARD, "Previous", prevButtonPos)
        self.prevBUTTON.Enable(False)
                
        self.nextBUTTON.Bind(wx.EVT_BUTTON, self.OnButton)
        self.prevBUTTON.Bind(wx.EVT_BUTTON, self.OnButton)
        
        #wx.EVT_PAINT(self, self.OnPaint)
        
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        self.Show(True)
        
        
    def OnButton(self, event):
        if event.GetId() == wx.ID_FORWARD:
            self.current += 1
            self.prevBUTTON.Enable(True)
            
            if(self.current == self.count - 1):
                self.nextBUTTON.SetLabel("Finish")
            
            if(self.current == self.count):
                self.Close()
            else:
                self.image.SetBitmap(self.tutorialBitmaps[self.current])
                self.text.SetLabel(self.tutorialStrings[self.current])
                
        if event.GetId() == wx.ID_BACKWARD:
            self.current -= 1
            self.image.SetBitmap(self.tutorialBitmaps[self.current])
            self.text.SetLabel(self.tutorialStrings[self.current])
            self.nextBUTTON.SetLabel("Next")
            if self.current == 0:
                    self.prevBUTTON.Enable(False)
                
        
    def OnClose(self, event):
        self.Destroy()
        
if __name__ == '__main__':
    app = wx.App(False)   
    TutorialGUI()  
    app.MainLoop()
        